package com.web.cms.pan.util;

import com.blue.jdbc.Page;
import com.web.cms.pan.message.OperatorLogRequest;
import com.web.cms.pan.message.OperatorLogResponse;
import com.web.cms.pan.model.OperatorLog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 网盘操作日志转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年04月09日
 */
public class OperatorLogConvertor
{
	private OperatorLogConvertor()
	{
	}
	
	public static OperatorLog toOperatorLog(OperatorLogRequest request)
	{
		if (request == null)
			return null;
		
		OperatorLog operatorLog = new OperatorLog();
		operatorLog.setId(request.getId());
		operatorLog.setUserId(request.getUserId());
		operatorLog.setDescp(request.getDescp());
		operatorLog.setCreateTime(request.getCreateTime());
		operatorLog.setExternalId(request.getExternalId());
		operatorLog.setExternalType(request.getExternalType());
		operatorLog.setOperateType(request.getOperateType());
		return operatorLog;
	}
	
	public static List<OperatorLog> toOperatorLog(List<OperatorLogRequest> requestList)
	{
		List<OperatorLog> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (OperatorLogRequest request : requestList)
		{
			list.add(toOperatorLog(request));
		}
		return list;
	}
	
	public static OperatorLogResponse toResponse(OperatorLog operatorLog)
	{
		if (operatorLog == null)
			return null;
		
		OperatorLogResponse response = new OperatorLogResponse();
		response.setId(operatorLog.getId());
		response.setUserId(operatorLog.getUserId());
		response.setDescp(operatorLog.getDescp());
		response.setCreateTime(operatorLog.getCreateTime());
		response.setExternalId(operatorLog.getExternalId());
		response.setExternalType(operatorLog.getExternalType());
		response.setOperateType(operatorLog.getOperateType());
		return response;
	}
	
	public static List<OperatorLogResponse> toResponse(List<OperatorLog> list)
	{
		List<OperatorLogResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (OperatorLog operatorLog : list)
		{
			responseList.add(toResponse(operatorLog));
		}
		return responseList;
	}
	
	public static Map<Integer, OperatorLogResponse> toResponse(Map<Integer, OperatorLog> map)
	{
		Map<Integer, OperatorLogResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, OperatorLog> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<OperatorLogResponse> toResponse(Page<OperatorLog> page)
	{
		if (page == null)
			return null;
		
		Page<OperatorLogResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
